package linter.linterjava.utils;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import linter.linterjava.custom.Constant;
import org.json.JSONException;

import javax.xml.ws.http.HTTPException;
import java.io.IOException;
import java.util.Random;

public class SmsUtil {


    public static String sendLogin(String phNumber,int tempid){
        Random random = new Random();
        int randomNumber = random.nextInt(9000) + 1000;
        String randomNumberAsString = String.valueOf(randomNumber);
        System.out.println();
        try{
            String[]  params = {randomNumberAsString};
            SmsSingleSender sender =  new SmsSingleSender(Constant.SmsAppid,Constant.SmsAapKey);
            SmsSingleSenderResult result = sender.sendWithParam("86", phNumber,
                    tempid, params, Constant.smsSign, "", "");
            System.out.println(result);
        }catch (HTTPException e) {
            // HTTP 响应码错误
            e.printStackTrace();
        } catch (JSONException e) {
            // JSON 解析错误
            e.printStackTrace();
        } catch (IOException e) {
            // 网络 IO 错误
            e.printStackTrace();
        } catch (com.github.qcloudsms.httpclient.HTTPException e) {
            e.printStackTrace();
        }
        return  randomNumberAsString;
    }
}
